package com.wangxiaotao.springcloud.service.impl;

import com.wangxiaotao.springcloud.service.IMessageProvider;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;

import java.util.UUID;

@EnableBinding(Source.class)//定义消息推送管道
@RequiredArgsConstructor
@Slf4j
public class MessageProviderImpl implements IMessageProvider {
    private final MessageChannel output;//消息发送管道

    @Override
    public String send() {
        String serial = UUID.randomUUID().toString();
        Message<String> build = MessageBuilder.withPayload(serial).build();
        output.send(build);
        log.info("****************** serial {}",serial);
        return null;
    }
}
